package com.ruoyi.system.util;

import java.io.File;

/**
 * 描述匹配工具
 */
public class DescriptionMatchingUtil {

    /**
     * 描述匹配
     *
     * @param path
     * @param description
     * @return
     */
    public static String descriptionMatch(String path, String description) {
        String result = description;
        if (path.contains("人脸")||path.contains("人像")) {
            result = faceImage(path, result);
        } else if (path.contains("专业场景")) {
            result = professionalScene(path, result);
        }

        return result;
    }


    /**
     * 人像匹配
     *
     * @param path        业务肤色类
     * @param description 描述
     * @return
     */
    public static String faceImage(String path, String description) {

        if (path.contains("白人")) {
            if (description.contains("黑肤色")) {
                description = description.replaceAll("黑肤色", "白肤色");
            } else if (description.contains("棕肤色")) {
                description = description.replaceAll("棕肤色", "白肤色");
            } else if (description.contains("黄肤色")) {
                description = description.replaceAll("黄肤色", "白肤色");
            }
        } else if (path.contains("棕人")) {
            if (description.contains("黑肤色")) {
                description = description.replaceAll("黑肤色", "棕肤色");
            } else if (description.contains("白肤色")) {
                description = description.replaceAll("白肤色", "棕肤色");
            } else if (description.contains("黄肤色")) {
                description = description.replaceAll("黄肤色", "棕肤色");
            }
        } else if (path.contains("黑人")) {
            if (description.contains("棕肤色")) {
                description = description.replaceAll("棕肤色", "黑肤色");
            } else if (description.contains("白肤色")) {
                description = description.replaceAll("白肤色", "黑肤色");
            } else if (description.contains("黄肤色")) {
                description = description.replaceAll("黄肤色", "黑肤色");
            }
        }else if (path.contains("黄人")) {
                if (description.contains("棕肤色")) {
                    description = description.replaceAll("棕肤色", "黄肤色");
                } else if (description.contains("白肤色")) {
                    description = description.replaceAll("白肤色", "黄肤色");
                } else if (description.contains("黑肤色")) {
                    description = description.replaceAll("黑肤色", "黄肤色");
                }
            }
        description = description.replace("没有佩戴任何物品","");
        return description;
    }

    /**
     * 专业场景
     *
     * @param path
     * @param description
     * @return
     */
    public static String professionalScene(String path, String description) {
        String result = description;
        File file = new File(path);
        File parentFile = file.getParentFile();
        String parentPathName = parentFile.getName();
        if (path.contains("专业场景")) {
            StringBuffer sb = new StringBuffer("标签：");
            result = description.replace("标签：", sb.append(parentPathName).append("-"));
            System.out.println(result);
        }
        return result;
    }

    public static void main(String[] args) {
        String fileCatagory = "E:\\workdata\\码诚科技\\采集翻译\\正式对接\\王芳\\本地\\第一批次20240924\\人脸头像\\男人\\棕人\\其他\\IMG_20240924_ZDO1.jpg";
        String description = "这是一张正常正面拍摄的图片，在正常光下，黄肤色青年男性，面部表情严肃，没有佩戴任何物品，穿着深色西装搭配白色衬衫和深色领带。";
        descriptionMatch(fileCatagory, description);
    }
}